'use strict';
const Service = require('egg').Service;
class SpecService extends Service {
  async addSpec(data) {
    const res = await this.app.mysql.insert('specification', data);
    if (res.affectedRows === 1) {
      return {
        code: 0,
      };
    }
    return {
      code: -1,
    };
  }
  // 获取商品型号
  async getSpecList() {
    const res = await this.app.mysql.select('specification', {
      orders: [[ 'sort_order', 'asc' ]],
    });
    return res;

  }
  // 根据id获取型号
  async getSpecById(id) {
    const res = await this.app.mysql.get('specification', { id });
    return res;
  }
  // 更新型号
  async updateSpec(data) {
    const res = await this.app.mysql.update('specification', data);
    if (res.affectedRows === 1) {
      return {
        code: 0,
      };
    }
    return {
      code: -1,
    };
  }
  // 删除型号
  async deleteSpecById(data) {
    const res = await this.app.mysql.delete('specification', data);
    if (res.affectedRows === 1) {
      return {
        code: 0,
      };
    }
    return {
      code: -1,
    };
  }

}
module.exports = SpecService;
